package com.corgi.message.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;
import java.util.concurrent.Future;

/**
 * @title: ProducerMain
 * @description: 生产者测试
 * @author: dengmiao
 * @create: 2019-10-10 17:01
 **/
public class ProducerMain {

	public static void main(String[] args) throws Exception {
		Properties prop = new Properties();
		prop.setProperty("bootstrap.servers", "localhost:9091,localhost:9092,localhost:9093");
		prop.put("key.serializer", StringSerializer.class);
		prop.put("value.serializer", StringSerializer.class);
		KafkaProducer kafkaProducer = new KafkaProducer(prop);

		ProducerRecord<String, String> record = new ProducerRecord("sf-2", 1, "message", "大家好");
		Future<RecordMetadata> future = kafkaProducer.send(record);

		RecordMetadata metadata = future.get();
		System.out.println(metadata);
	}
}
